package com.example.myspringboot.util;

import java.io.*;
import java.util.zip.GZIPOutputStream;

/**
 * @author cy
 * @date 2024/2/5
 * 文件工具类
 */
public class FileUtil {
    private FileUtil() {
    }

    /**
     * 压缩文件为gz
     *
     * @param fileIn  输入文件
     * @param fileOut 输出路径
     * @throws IOException
     */
    public static void toGzipFile(File fileIn, String fileOut) throws IOException {
        try (
                FileInputStream stream = new FileInputStream(fileIn);
                GZIPOutputStream gzipOutputStream = new GZIPOutputStream(new FileOutputStream(fileOut));
        ) {
            byte[] bytes = new byte[1024 * 10 * 10];
            int num;
            while ((num = stream.read(bytes)) != -1) {
                gzipOutputStream.write(bytes, 0, num);
            }
        }
    }
}
